var zfesTreeGrid = {

   loadTable: function(treeGridDom,columnx ){
    var $table = treeGridDom;
    
     $table.bootstrapTable({
            data:data,
            idField: 'id',
            dataType:'json',
            columns: $.extend( { field: 'check',  checkbox: true, formatter: function (value, row, index) {
                        if (row.check == true) {
                            return {  checked: true };
                        }
                      }
                    } , columnx),
                
            //在哪一列展开树形
            treeShowField: 'name',
            //指定父id列
            parentIdField: 'pid',
 
            onResetView: function(data) {
                //console.log('load');
                $table.treegrid({
                    initialState: 'collapsed',// 所有节点都折叠
                    // initialState: 'expanded',// 所有节点都展开，默认展开
                    treeColumn: 1,
                    // expanderExpandedClass: 'glyphicon glyphicon-minus',  //图标样式
                    // expanderCollapsedClass: 'glyphicon glyphicon-plus',
                    onChange: function() {
                        $table.bootstrapTable('resetWidth');
                    }
                });
 
                //只展开树形的第一级节点
                $table.treegrid('getRootNodes').treegrid('expand');
 
            },
            onCheck:function(row){
                var datas = $table.bootstrapTable('getData');
                // 勾选子类
                selectChilds(datas,row,"id","pid",true);
 
                // 勾选父类
                selectParentChecked(datas,row,"id","pid")
 
                // 刷新数据
                $table.bootstrapTable('load', datas);
            },
 
            onUncheck:function(row){
                var datas = $table.bootstrapTable('getData');
                selectChilds(datas,row,"id","pid",false);
                $table.bootstrapTable('load', datas);
            },
            
        });
   }
    selectChilds: function (datas,row,id,pid,checked) {
        for(var i in datas){
            if(datas[i][pid] == row[id]){
                datas[i].check=checked;
                selectChilds(datas,datas[i],id,pid,checked);
            };
        }
    }
 
     selectParentChecked: function(datas,row,id,pid){
        for(var i in datas){
            if(datas[i][id] == row[pid]){
                datas[i].check=true;
                selectParentChecked(datas,datas[i],id,pid);
            };
        }
    }
	
}
